--地縛神の聖域－ナスカの地上絵
function c77239994.initial_effect(c)
	--Activate
	local e0=Effect.CreateEffect(c)
	e0:SetProperty(EFFECT_CANNOT_DISABLE)
	e0:SetType(EFFECT_TYPE_ACTIVATE)
	e0:SetCode(EVENT_FREE_CHAIN)
	c:RegisterEffect(e0)
	--unaffectable
	local e1=Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_SINGLE)
	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
	e1:SetRange(LOCATION_FZONE)
	e1:SetCode(EFFECT_IMMUNE_EFFECT)
	e1:SetValue(c77239994.efilter)
	c:RegisterEffect(e1)
	--immune
	local e2=e1:Clone()
	e2:SetCode(EFFECT_CANNOT_CHANGE_CONTROL)
	e2:SetValue(c77239994.efilter)
	c:RegisterEffect(e2)
	local e3=e2:Clone()
	e3:SetCode(EFFECT_CANNOT_TO_DECK)
	c:RegisterEffect(e3)
	local e4=e2:Clone()
	e4:SetCode(EFFECT_CANNOT_TO_HAND)
	c:RegisterEffect(e4)
	local e5=e2:Clone()
	e5:SetCode(EFFECT_CANNOT_REMOVE)
	c:RegisterEffect(e5)
	local e6=e2:Clone()
	e6:SetCode(EFFECT_CANNOT_TO_GRAVE)
	c:RegisterEffect(e6)
	local e7=e2:Clone()
	e7:SetCode(EFFECT_CANNOT_USE_AS_COST)
	c:RegisterEffect(e7)
	--atk up
	local e8=Effect.CreateEffect(c)
	e8:SetType(EFFECT_TYPE_FIELD)
	e8:SetCode(EFFECT_UPDATE_ATTACK)
	e8:SetRange(LOCATION_FZONE)
	e8:SetTargetRange(LOCATION_MZONE,LOCATION_MZONE)
	e8:SetValue(c77239994.val)
	c:RegisterEffect(e8)
	local e9=e8:Clone()
	e9:SetCode(EFFECT_UPDATE_DEFENSE)
	c:RegisterEffect(e9)
	--spsummon
	local e10=Effect.CreateEffect(c)
	e10:SetDescription(aux.Stringid(77239994,0))
	e10:SetCategory(CATEGORY_SPECIAL_SUMMON)
	e10:SetType(EFFECT_TYPE_IGNITION)
	e10:SetRange(LOCATION_FZONE)
	e10:SetCountLimit(1)
	e10:SetTarget(c77239994.sptg)
	e10:SetOperation(c77239994.spop)
	c:RegisterEffect(e10)
	--no damage
	local e11=Effect.CreateEffect(c)
	e11:SetType(EFFECT_TYPE_FIELD)
	e11:SetCode(EFFECT_CHANGE_DAMAGE)
	e11:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
	e11:SetRange(LOCATION_FZONE)
	e11:SetTargetRange(1,0)
	e11:SetValue(0)
	e11:SetCondition(c77239994.damcon)
	c:RegisterEffect(e11)
	local e12=e11:Clone()
	e12:SetCode(EFFECT_NO_EFFECT_DAMAGE)
	c:RegisterEffect(e12)
	local e13=e11:Clone()
	e13:SetCode(EFFECT_NO_BATTLE_DAMAGE)
	c:RegisterEffect(e13)
	--immune
	--local e13=Effect.CreateEffect(c)
	--e13:SetType(EFFECT_TYPE_FIELD)
	--e13:SetCode(EFFECT_IMMUNE_EFFECT)
	--e13:SetRange(LOCATION_FZONE)
	--e13:SetTargetRange(LOCATION_MZONE,0)
	--e13:SetTarget(aux.TargetBoolFunction(Card.IsSetCard,0x21))
	--e13:SetValue(c77239994.efilter1)
	--c:RegisterEffect(e13)
	--
	local e14=Effect.CreateEffect(c)
	e14:SetType(EFFECT_TYPE_FIELD)
	e14:SetCode(77239994)
	e14:SetRange(LOCATION_SZONE)
	e14:SetTargetRange(LOCATION_MZONE,0)
	e14:SetTarget(aux.TargetBoolFunction(Card.IsSetCard,0x21))
	c:RegisterEffect(e14)
end
function c77239994.efilter(e,te)
	return te:GetOwner()~=e:GetOwner()
end
function c77239994.val(e,c)
	return c:IsSetCard(0x21) and 1000
end
function c77239994.filter(c,e,tp)
	return c:IsSetCard(0x21) and c:IsCanBeSpecialSummoned(e,0,tp,false,false)
end
function c77239994.sptg(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return true end
	Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,tp,0x13)
end
function c77239994.spop(e,tp,eg,ep,ev,re,r,rp)
	if Duel.GetLocationCount(tp,LOCATION_MZONE)<=0 then return end
	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)
	local g=Duel.SelectMatchingCard(tp,aux.NecroValleyFilter(c77239994.filter),tp,0x13,0,1,1,nil,e,tp)
	local tc=g:GetFirst()
	local c=e:GetHandler()
	if tc then
		Duel.SpecialSummonStep(tc,0,tp,tp,false,false,POS_FACEUP)
		local e1=Effect.CreateEffect(c)
		e1:SetType(EFFECT_TYPE_SINGLE)
		e1:SetCode(EFFECT_INDESTRUCTABLE_COUNT)
		e1:SetCountLimit(2)
		e1:SetValue(1)
		e1:SetReset(RESET_EVENT+0x1fe0000)
		tc:RegisterEffect(e1)
		--immune
		local e2=Effect.CreateEffect(e:GetHandler())
		e2:SetType(EFFECT_TYPE_SINGLE)
		e2:SetCode(EFFECT_IMMUNE_EFFECT)
		e2:SetValue(c77239994.efilter1)
		e2:SetReset(RESET_EVENT+0x1fe0000)
		tc:RegisterEffect(e2)
		Duel.SpecialSummonComplete()
	end
end
function c77239994.cfilter(c)
	return c:IsFaceup() and c:IsSetCard(0x21)
end
function c77239994.damcon(e,tp,eg,ep,ev,re,r,rp)
	return Duel.IsExistingMatchingCard(c77239994.cfilter,e:GetHandlerPlayer(),LOCATION_MZONE,0,1,nil)
end
function c77239994.efilter1(e,re)
	return e:GetOwner()~=re:GetOwner() and re:IsActiveType(TYPE_MONSTER)
end
